const router = require('koa-router')() // 一边导入一边实例化
const result = require('../../config/result.js')
// const { regcheck,checking } = require('../../config/checking.js')
const bodyParser = require('koa-bodyparser')
// 操作数据库的接口
const { getToken, Updateurl } = require('../../config/databaseapi.js')
// 注册接口
router.post('/edituserlist', async (ctx) => {
	console.log('调用编辑党员信息接口')
	// console.log(ctx.request.body);
	let {_id,name,phone,sex,age,join_time,position,work_status,work_unit} = ctx.request.body;
	if(name==='' || phone==='' || sex==='' || age==='' || join_time==='' || work_status===''  || work_unit==='' || position===''){
		ctx.body = {msg:"修改失败",status:0}
	}else{
		let query = `db.collection("member_info").where({_id:"${_id}"}).update({data:{name:"${name}",phone:"${phone}",sex:"${sex}",age:"${age}",work_unit:"${work_unit}",work_status:"${work_status}",position:"${position}",join_time:"${join_time}",}})`
		let res = await new getToken().posteve(Updateurl,query)
		// console.log('修改用户',res)
		if(res.errcode === 0){
			ctx.body = {msg:"修改成功",status:1}
		}else{
			ctx.body = {msg:"修改失败",status:0}
		}
	}

})

module.exports = router.routes()